require "Dialogs"

Arena.Resize(565, 130)
Player.sprite.alpha = 0
Player.SetControlOverride(true)

state = 0
maxjump = 45
jump = 0
newpX = Player.absx
newpY = Player.absy
tableaux = 0

if Encounter["StatusPhase3"] == "Flee" then
	Bubble("", "", 0, 0, 0, 0, 1)
	timer = 0
else
	timer = -2
end
slamtimer = 0
shake = {}
phases = {0, 0}
Paps = {X = 330, Y = 240}
Sans = {X = 490, Y = 261}

GB = {}
Sprites = {}
Bones = {}
HuesosSuelo = {}
Z = {}

SetPPCollision(true)

Bubble("something", "rightwide", 0, 0, 0, 0, 1)
Bubble("something", "rightwide", 0, 0, 0, 0, 2)
Bubble("", "", 0, 0, 0, 0, 1)
Bubble("", "", 0, 0, 0, 0, 2)

function SummonWarning(num)
	Audio.PlaySound("encounter")
	Warning = {CreateSprite("Pixel", "BelowBullet"), CreateSprite("Pixel", "BelowBullet"), CreateSprite("Pixel", "BelowBullet")}
	Warning[1].color = {0.5, 0, 0}
	Warning[2].color = {0.5, 0, 0}
	Warning[3].color = {0.5, 0, 0}
	if num == 1 then
		Warning[1].Scale(2, 40)
		Warning[2].Scale(2, 40)
		Warning[3].Scale(Arena.width, 2)
		Warning[1].SetVar("Pos", {Arena.x + Arena.width/2 - 1, Arena.y + 25})
		Warning[2].SetVar("Pos", {Arena.x - Arena.width/2 + 1, Arena.y + 25})
		Warning[3].SetVar("Pos", {Arena.x, Arena.y + 44})
	elseif num == 2 then
		Warning[1].Scale(40, 2)
		Warning[2].Scale(40, 2)
		Warning[3].Scale(2, Arena.height)
		Warning[1].SetVar("Pos", {Arena.x + Arena.width/2 - 20, Arena.y + 4 + Arena.height})
		Warning[2].SetVar("Pos", {Arena.x + Arena.width/2 - 20, Arena.y + 6})
		Warning[3].SetVar("Pos", {Arena.x + Arena.width/2 - 39, Arena.y + 5 + Arena.height/2})
	elseif num == 3 then
		Warning[1].Scale(2, 40)
		Warning[2].Scale(2, 40)
		Warning[3].Scale(Arena.width, 2)
		Warning[1].SetVar("Pos", {Arena.x + Arena.width/2 - 1, Arena.y - 15 + Arena.height})
		Warning[2].SetVar("Pos", {Arena.x - Arena.width/2 + 1, Arena.y - 15 + Arena.height})
		Warning[3].SetVar("Pos", {Arena.x, Arena.y - 34 + Arena.height})
	else
		Warning[1].Scale(40, 2)
		Warning[2].Scale(40, 2)
		Warning[3].Scale(2, Arena.height)
		Warning[1].SetVar("Pos", {Arena.x - Arena.width/2 + 20, Arena.y + 4 + Arena.height})
		Warning[2].SetVar("Pos", {Arena.x - Arena.width/2 + 20, Arena.y + 6})
		Warning[3].SetVar("Pos", {Arena.x - Arena.width/2 + 39, Arena.y + 5 + Arena.height/2})
	end
	table.insert(Sprites, Warning[1])
	table.insert(Sprites, Warning[2])
	table.insert(Sprites, Warning[3])
end

function DestroyWarning()
	Audio.PlaySound("pierce")
	Warning[1].Remove()
	Warning[2].Remove()
	Warning[3].Remove()
	Warning = nil
end

function RecolorSoul()
	if state >= 1 and state <= 3 then
		Player.sprite.color = {0,60/255,1}
		Player.sprite.rotation = 0
	elseif state == 4 then
		Player.sprite.color = {0,60/255,1}
		Player.sprite.rotation = 270
	elseif state == 5 then
		Player.sprite.color = {0,60/255,1}
		Player.sprite.rotation = 180
	elseif state == 6 then
		Player.sprite.color = {0,60/255,1}
		Player.sprite.rotation = 90
	else
		Player.sprite.color = {1.0,0.0,0.0}
		Player.sprite.rotation = 0
	end
end

RecolorSoul()

function Update()
	DialogUpdate()
	if timer == -2 then
		if Encounter["StatusPhase3"][1] == "Check Papyrus" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans]huh?[w:5] no[w:5], no me[next] gusta decir \"Nyeh heh heh!\".", "leftwide", 310.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans]huh?[w:5] no[w:5], i don't[next] like to say \"Nyeh heh heh!\".", "leftwide", 310.5, 335, 10, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Flirt" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans]eerr...[w:5] [func:SetSansHead,Joking]creo que el chico\nqui[next]ere follarte.", "leftwide", 310.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans]eerr...[w:5] [func:SetSansHead,Joking]i think the kiddo\nwan[next]ts to fuck you.", "leftwide", 310.5, 335, 10, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Cry" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans]mira lo que has hec[next]ho papyrus.", "leftwide", 310.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans]look what you have do[next]ne papyrus.", "leftwide", 310.5, 335, 10, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Pun" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans]hehehe[w:5], supongo que es ho[next]ra de una broma.", "leftwide", 310.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans]hehehe[w:5], guess it's ti[next]me for a pun.", "leftwide", 310.5, 335, 10, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Fight Papyrus" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans][func:SetSansHead,Worried]cómo conseguiste 9999\nDE[next]F? eso es solo injusto.", "leftwide", 310.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans][func:SetSansHead,Worried]how did you get 9999\nDE[next]F? that's just unfair.", "leftwide", 310.5, 335, 10, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Miss Papyrus" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans][func:SetSansHead,Worried]huh?[w:5] qué pasa chi[next]co? no esperabas que estuviera aquí?", "leftwide", 310.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans][func:SetSansHead,Worried]huh?[w:5] what's wrong kid[next]do? you didn't expected me to be here?", "leftwide", 310.5, 335, 10, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Item" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans]es ese tu espag[next]ueti papyrus?", "leftwide", 310.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans]is that your spagh[next]etti papyrus?", "leftwide", 310.5, 335, 10, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Spare" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans]hey[w:5], creo que el chico\na cambi[next]ado, deberíamos mostrar piedad también?", "leftwide", 310.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans]hey[w:5], i think the kiddo\nhas chan[next]ged, should we show mercy too?", "leftwide", 310.5, 335, 10, 90, 1)
			end
		end
		timer = -1
	elseif timer == -1 and Bubbles[1] and not Bubbles[1].Activo then
		if Encounter["StatusPhase3"][1] == "Check Papyrus" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]ESTABA HABLANDO\nDE MI!!!", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]IT WAS TALKING\nABOUT ME!!!", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Flirt" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5][func:SetHead,Angry]PARA SANS!!!", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5][func:SetHead,Angry]STOP SANS!!!", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Cry" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5][func:SetHead,Angry]ÉLLOS PIDIERON\nESTO!!!", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5][func:SetHead,Angry]THEY ASKED FOR\nTHIS!!!", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Pun" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5][func:SetHead,Angry]SANS!!![w:5] NO AHORA!!!", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5][func:SetHead,Angry]SANS!!![w:5] NOT NOW!!!", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Fight Papyrus" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]NO LO SE SANS!!!", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]I DON'T KNOW\nSANS!!!", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Miss Papyrus" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]SOLO TIENEN\nMIEDO!!!", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]THEY'RE JUST\nSCARED!!!", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Item" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]HECHO POR EL\nGRAN PAPYRUS!!!", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]MADE BY THE\nGREAT PAPYRUS!!!", "rightwide", 490.5, 395, 40, 90, 1)
			end
		elseif Encounter["StatusPhase3"][1] == "Spare" then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]TODAVÍA TIENEN\nQUE APRENDER SU\nLECCIÓN!!!", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]THEY STILL NEED\nTO LEARN THEIR\nLESSON!!!", "rightwide", 490.5, 395, 40, 90, 1)
			end
		end
		timer = 0
	elseif timer == 0 and Bubbles[1] and not Bubbles[1].Activo then
		Encounter.Call("SetSansHead","Normal")
		Encounter.Call("SetHead","Normal 1")
		if Encounter["Animation"] == "Alocado" then
			Encounter.Call("AttackAnim", 2)
		elseif Encounter["Animation"] == "None" or (Encounter["Animation"] == "Cambio" and Encounter["AnimationStop"]) then
			Encounter["Animation"] = "Calmado"
			Encounter["vel"] = 0
		end
		Encounter["Sans"]["Animation"] = "Stop"
		Encounter["Sans"]["Timer"] = 0
		Arena.Resize(250, 130)
		Player.sprite.alpha = 1
		Player.sprite.color = {0,60/255,1}
		state = 1
		Encounter.Call("ContinueMusic")
		timer = 1
	elseif timer > 0 and timer <= 20 then
		timer = timer + 1
	elseif timer == 21 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			Bubble("[noskip][font:papyrus][voice:papyrus]Quiero una pelea\njusta![w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
		else
			Bubble("[noskip][font:papyrus][voice:papyrus]I want a fair\nfight![w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
		end
		timer = 22
	elseif timer == 22 then
		if NewAudio.GetPlayTime("One") > 2.4 and phases[1] == 0 then
			Bubble("", "", 0, 0, 0, 0, 1)
			Encounter["Animation"] = "None"
			Diff = {122 - Encounter["Body"].y, Encounter["Body"].y, -14 + 8*math.sin(math.rad(360/90*Encounter["vel"])), 45 - Encounter["Head"].y, Encounter["Head"].y}
			Heart = CreateSprite("Specials/Soul","Top")
			Heart.color = {0,60/255,1}
			Audio["healsound"] = "nothing"
			Audio["hurtsound"] = "nothing"
			phases[1] = 1
		elseif NewAudio.GetPlayTime("One") > 2.4 and phases[1] == 1 then
			if NewAudio.GetPlayTime("One") <= 2.85 then
				Encounter["Body"].MoveTo(-8 - 6*math.sin(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 2.4))), Diff[2] + Diff[1]/0.45*(NewAudio.GetPlayTime("One") - 2.4))
				Encounter["Head"].MoveTo(1 - 2*math.sin(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 2.4))), Diff[5] + Diff[4]/0.45*(NewAudio.GetPlayTime("One") - 2.4))
				Encounter["HandL"].rotation = -8*math.sin(math.rad(360/90*Encounter["vel"])) + Diff[3]/0.45*(NewAudio.GetPlayTime("One") - 2.4)
				Encounter["HandR"].rotation = -30*math.sin(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 2.4)))
				Encounter["HandL"].MoveTo(Encounter["Body"].absx - 44, Encounter["Body"].absy - 13)
				Encounter["HandR"].MoveTo(Encounter["Body"].absx + 43, Encounter["Body"].absy - 3)
				for i=2,#Encounter["LegsParts"] do
					local sprite = Encounter["LegsParts"][i]
					sprite.MoveTo(Encounter["PiernasX"] - sprite.GetVar("intensity")*math.sin(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 2.4))), Encounter["PiernasY"] + sprite.GetVar("Y"))
				end
				Encounter.Call("SetCustomHP", {110 - 86*math.sin(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 2.4))), 19, 92 - math.floor(72*math.sin(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 2.4)))), 184, true})
			else
				Encounter["Body"].MoveTo(-14, 122)
				Encounter["Head"].MoveTo(-1, 45)
				Encounter["HandL"].rotation = -14
				Encounter["HandR"].rotation = -30
				Encounter["HandL"].MoveTo(Encounter["Body"].absx - 44, Encounter["Body"].absy - 13)
				Encounter["HandR"].MoveTo(Encounter["Body"].absx + 43, Encounter["Body"].absy - 3)
				for i=2,#Encounter["LegsParts"] do
					local sprite = Encounter["LegsParts"][i]
					sprite.MoveTo(Encounter["PiernasX"] - sprite.GetVar("intensity"), Encounter["PiernasY"] + sprite.GetVar("Y"))
				end
				Encounter.Call("SetCustomHP", {24, 19, 20, 184, true})
				Encounter.Call("SetSansHead","Surprised")
				Audio.PlaySound("pierce")
				phases[1] = 2
			end
		elseif NewAudio.GetPlayTime("One") > 2.85 and phases[1] == 2 then
			if NewAudio.GetPlayTime("One") <= 3 then
				Encounter["Body"].MoveTo(-8 - 6*math.sin(math.rad(180/0.15*(NewAudio.GetPlayTime("One") - 2.775))), 124 - math.max(2*math.sin(math.rad(180/0.15*(NewAudio.GetPlayTime("One") - 2.775))), 0))
				Encounter["Head"].MoveTo(1 - 2*math.sin(math.rad(180/0.15*(NewAudio.GetPlayTime("One") - 2.775))), 47 - math.max(2*math.sin(math.rad(180/0.15*(NewAudio.GetPlayTime("One") - 2.775))), 0))
				Encounter["HandL"].rotation = -14*math.sin(math.rad(180/0.15*(NewAudio.GetPlayTime("One") - 2.775)))
				Encounter["HandR"].rotation = 17.5 - 27.5*math.sin(math.rad(180/0.15*(NewAudio.GetPlayTime("One") - 2.775)))
				Encounter["HandL"].MoveTo(Encounter["Body"].absx - 44, Encounter["Body"].absy - 13)
				Encounter["HandR"].MoveTo(Encounter["Body"].absx + 43 + 10*math.sin(math.rad(90/0.15*(NewAudio.GetPlayTime("One") - 2.85))), Encounter["Body"].absy + 7 - 10*math.cos(math.rad(90/0.15*(NewAudio.GetPlayTime("One") - 2.85))))
				for i=2,#Encounter["LegsParts"] do
					local sprite = Encounter["LegsParts"][i]
					sprite.MoveTo(Encounter["PiernasX"] - sprite.GetVar("intensity")*math.sin(math.rad(180/0.15*(NewAudio.GetPlayTime("One") - 2.775))), Encounter["PiernasY"] + sprite.GetVar("Y"))
				end
				Encounter.Call("SetCustomHP", {112 - 88*math.cos(math.rad(180/0.15*(NewAudio.GetPlayTime("One") - 2.85))), 19, 102 - math.ceil(82*math.cos(math.rad(180/0.15*(NewAudio.GetPlayTime("One") - 2.85)))), 184, true})
			else
				Encounter["Body"].MoveTo(-2, 124)
				Encounter["Head"].MoveTo(3, 47)
				Encounter["HandL"].rotation = 14
				Encounter["HandR"].rotation = 45
				Encounter["HandL"].MoveTo(Encounter["Body"].absx - 44, Encounter["Body"].absy - 13)
				Encounter["HandR"].MoveTo(Encounter["Body"].absx + 53, Encounter["Body"].absy + 7)
				for i=2,#Encounter["LegsParts"] do
					local sprite = Encounter["LegsParts"][i]
					sprite.MoveTo(Encounter["PiernasX"] + sprite.GetVar("intensity"), Encounter["PiernasY"] + sprite.GetVar("Y"))
				end
				Player.Hurt(0, 0.02)
				Encounter.Call("SetCustomHP", {200, 19, 184, 184, true})
				Audio["healsound"] = "healsound"
				Audio["hurtsound"] = "hurtsound"
				phases[1] = 3
			end
		elseif NewAudio.GetPlayTime("One") > 3.15 and phases[1] == 3 then
			if NewAudio.GetPlayTime("One") <= 3.6 then
				Encounter["Body"].MoveTo(-8 - 6*math.sin(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 1.8))), 124)
				Encounter["Head"].MoveTo(1 - 2*math.sin(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 1.8))), 47)
				Encounter["HandL"].rotation = -14*math.sin(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 1.8)))
				Encounter["HandR"].rotation = -45*math.sin(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 1.8)))
				Encounter["HandL"].MoveTo(Encounter["Body"].absx - 44, Encounter["Body"].absy - 13)
				Encounter["HandR"].MoveTo(Encounter["Body"].absx + 43 + 10*math.cos(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 3.15))), Encounter["Body"].absy + 7 - 10*math.sin(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 3.15))))
				for i=2,#Encounter["LegsParts"] do
					local sprite = Encounter["LegsParts"][i]
					sprite.MoveTo(Encounter["PiernasX"] - sprite.GetVar("intensity")*math.sin(math.rad(90/0.45*(NewAudio.GetPlayTime("One") - 1.8))), Encounter["PiernasY"] + sprite.GetVar("Y"))
				end
			else
				Encounter["Body"].MoveTo(-8, 124)
				Encounter["Head"].MoveTo(1, 47)
				Encounter["HandL"].rotation = 0
				Encounter["HandR"].rotation = 0
				Encounter["HandL"].MoveTo(Encounter["Body"].absx - 44, Encounter["Body"].absy - 13)
				Encounter["HandR"].MoveTo(Encounter["Body"].absx + 43, Encounter["Body"].absy - 3)
				for i=2,#Encounter["LegsParts"] do
					local sprite = Encounter["LegsParts"][i]
					sprite.MoveTo(Encounter["PiernasX"], Encounter["PiernasY"] + sprite.GetVar("Y"))
				end
				phases[1] = 4
			end
		elseif NewAudio.GetPlayTime("One") > 3.9 and phases[1] == 4 then
			Audio.PlaySound("ding")
			Encounter.Call("ConfigurateKR", {false, true})
			FakeKR = CreateSprite("Fake UI, KR and HP Library Sprites/KR","Top")
			FakeKR.MoveTo(254, 410)
			FakeKR.alpha = 0
			phases[1] = 5
		elseif NewAudio.GetPlayTime("One") > 3.9 and phases[1] == 5 then
			Encounter.Call("SetHead","Normal 3")
			if NewAudio.GetPlayTime("One") <= 4 then
				Encounter["Head"].MoveTo(1 - 10 + math.abs(10*math.cos(math.rad(90/0.1*(NewAudio.GetPlayTime("One") - 3.9)))), 47 - 2 + (math.cos(math.rad(90/0.1*(NewAudio.GetPlayTime("One") - 3.9)))*math.cos(math.rad(90/0.1*(NewAudio.GetPlayTime("One") - 3.9))))*2)
				Encounter["Head"].rotation = 10 - math.abs(10*math.cos(math.rad(90/0.1*(NewAudio.GetPlayTime("One") - 3.9))))
			else
				Encounter["Head"].MoveTo(-9, 45)
				Encounter["Head"].rotation = 10
				phases[1] = 6
			end
		elseif NewAudio.GetPlayTime("One") > 4.1 and phases[1] == 6 then
			Encounter.Call("SetHead","Normal 1")
			if NewAudio.GetPlayTime("One") <= 4.2 then
				Encounter["Head"].MoveTo(1 - 10 + math.abs(10*math.cos(math.rad(90/0.1*(NewAudio.GetPlayTime("One") - 4)))), 47 - 2 + (math.cos(math.rad(90/0.1*(NewAudio.GetPlayTime("One") - 4)))*math.cos(math.rad(90/0.1*(NewAudio.GetPlayTime("One") - 4))))*2)
				Encounter["Head"].rotation = 10 - math.abs(10*math.cos(math.rad(90/0.1*(NewAudio.GetPlayTime("One") - 4))))
			else
				Encounter["Head"].MoveTo(1, 47)
				Encounter["Head"].rotation = 0
				phases[1] = 7
			end
		elseif phases[1] == 7 then
			Encounter.Call("SetSansHead","Worried")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans]cómo es eso justo?[w:10000000] ", "leftwide", 310.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans]how is that fair?[w:10000000] ", "leftwide", 310.5, 335, 10, 90, 1)
			end
			phases[1] = 8
		elseif NewAudio.GetPlayTime("One") > 5.3 and phases[1] == 8 then
			Encounter.Call("SetSansHead","Joking")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus]Digamos que...[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus]Let's just say...[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			end
			phases[1] = 9
		elseif NewAudio.GetPlayTime("One") > 6.7 and phases[1] == 9 then
			if not R then
				Bubble("", "", 0, 0, 0, 0, 1)
				FakeKR.Set("Specials/K")
				R = CreateSprite("Specials/R")
				R.MoveTo(254, 410)
				R.Scale(2, 2)
				Audio.PlaySound("throw")
			end
			if NewAudio.GetPlayTime("One") <= 7.2 then
				FakeKR.MoveTo(254, 410 - 40/0.5*(NewAudio.GetPlayTime("One") - 6.7))
				R.MoveTo(254, 410 + 40/0.5*(NewAudio.GetPlayTime("One") - 6.7))
				FakeKR.alpha = 1 - 2/0.5*(NewAudio.GetPlayTime("One") - 6.7)
				R.alpha = 1 - 2/0.5*(NewAudio.GetPlayTime("One") - 6.7)
			else
				FakeKR.Remove()
				R.Remove()
				FakeKR = nil
				R = nil
				phases[1] = 10
			end
		elseif NewAudio.GetPlayTime("One") > 7.5 and phases[1] == 10 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Me ha crecido\nmucho la columna\nvertebral.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus]I've grown a lot\nof backbone.[w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
			end
			phases[1] = 11
		elseif NewAudio.GetPlayTime("One") > 8.35 and phases[1] == 11 then
			if NewAudio.GetPlayTime("One") <= 9.6 then
				if (NewAudio.GetPlayTime("One") - 8.35)%0.5 < 0.125 then
					Encounter["Head"].MoveTo(1 - 10 + 10*math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35))), 47 - 2 + (math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35)))*math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35))))*2)
					Encounter["Head"].rotation = 10 - 10*math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35)))
					Encounter.Call("SetHead", "Normal 1")
				elseif (NewAudio.GetPlayTime("One") - 8.35)%0.5 < 0.25 then
					Encounter["Head"].MoveTo(1 - 10 - 10*math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35))), 47 - 2 + (math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35)))*math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35))))*2)
					Encounter["Head"].rotation = 10 + 10*math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35)))
					Encounter.Call("SetHead", "Normal 3")
				elseif (NewAudio.GetPlayTime("One") - 8.35)%0.5 < 0.375 then
					Encounter["Head"].MoveTo(1 + 10 + 10*math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35))), 47 - 2 + (math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35)))*math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35))))*2)
					Encounter["Head"].rotation = -10 - 10*math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35)))
					Encounter.Call("SetHead", "Normal 1")
				else
					Encounter["Head"].MoveTo(1 + 10 - 10*math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35))), 47 - 2 + (math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35)))*math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35))))*2)
					Encounter["Head"].rotation = -10 + 10*math.cos(math.rad(360/0.5*(NewAudio.GetPlayTime("One") - 8.35)))
					Encounter.Call("SetHead", "Normal 2")
				end
			else
				Encounter["Head"].MoveTo(1, 47)
				Encounter["Head"].rotation = 0
				Encounter.Call("SetHead", "Normal 1")
				Encounter.Call("SetSansHead", "Normal")
				Encounter["Animation"] = "Calmado"
				Encounter["vel"] = 0
				Encounter["Sans"]["Animation"] = "Normal"
				Encounter["Sans"]["Timer"] = 0
				Bubble("", "", 0, 0, 0, 0, 1)
				state = 2
				table.insert(Bones, {Body = CreateProjectileAbs("Bullets/Bones/Body", 448, 108), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Scale = 16, Vel = -2.5})
				phases[1] = 12
			end
		elseif NewAudio.GetPlayTime("One") > 11.78 and phases[1] == 12 then
			table.insert(Bones, {Body = CreateProjectileAbs("Bullets/Bones/Body", 448, 116), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Scale = 32, Vel = -2.5})
			phases[1] = 13
		elseif NewAudio.GetPlayTime("One") > 13.96 and phases[1] == 13 then
			table.insert(Bones, {Body = CreateProjectileAbs("Bullets/Bones/Body", 448, 140), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Scale = 80, Vel = -2.5})
			phases[1] = 14
		elseif NewAudio.GetPlayTime("One") > 14.69 and phases[1] == 14 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans]uy, mi turno.[w:10000000] ", "leftwide", 310.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans]oops, my turn.[w:10000000] ", "leftwide", 310.5, 335, 10, 90, 1)
			end
			phases[1] = 15
		elseif NewAudio.GetPlayTime("One") > 15.58 and phases[1] == 15 then
			Arena.Resize(130, 130)
			Bubble("", "", 0, 0, 0, 0, 1)
			state = 3
			maxjump = 40
			if NewAudio.GetPlayTime("One") <= 15.78 then
				Paps = {X = 330 - 170*math.sin(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 15.58))), Y = 240}
				Sans = {X = 490 - 170*math.sin(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 15.58))), Y = 261}
				Encounter.Call("PapyrusAlpha", 1 - math.sin(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 15.58)))/2)
				Encounter.Call("SansAlpha", 0.5 + math.sin(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 15.58)))/2)
			else
				Paps = {X = 160, Y = 240}
				Sans = {X = 320, Y = 261}
				Encounter.Call("PapyrusAlpha", 0.5)
				Encounter.Call("SansAlpha", 1)
				phases[1] = 16
			end
		elseif NewAudio.GetPlayTime("One") > 16.1 and phases[1] == 16 then
			if math.random(2) == 1 then
				Encounter["Sans"]["Animation"] = "Right"
				state = 6
				jump = -100
				SummonWarning(2)
			else
				Encounter["Sans"]["Animation"] = "Left"
				state = 4
				jump = -100
				SummonWarning(4)
			end
			Encounter["Sans"]["Timer2"] = 0
			RecolorSoul()
			phases[1] = 17
		elseif NewAudio.GetPlayTime("One") > 16.8 and phases[1] == 17 then
			DestroyWarning()
			if state == 6 then
				for i=Arena.y + 10,Arena.y + Arena.height,12 do
					table.insert(HuesosSuelo, {Misil = CreateProjectileAbs("Bullets/Bones/BodyS", Arena.x + Arena.width/2, i), Head = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Scale = {MaxHeight = 34, Vel = 4}, Rotacion = 90, Duration = 20})
				end
			else
				for i=Arena.y + 10,Arena.y + Arena.height,12 do
					table.insert(HuesosSuelo, {Misil = CreateProjectileAbs("Bullets/Bones/BodyS", Arena.x - Arena.width/2, i), Head = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Scale = {MaxHeight = 34, Vel = 4}, Rotacion = 270, Duration = 20})
				end
			end
			phases[1] = 18
		elseif NewAudio.GetPlayTime("One") > 17.7 and phases[1] == 18 then
			Encounter["Sans"]["Animation"] = "Normal"
			if NewAudio.GetPlayTime("One") <= 18 then
				Paps = {X = 160 + 170*math.sin(math.rad(90/0.3*(NewAudio.GetPlayTime("One") - 17.7))), Y = 240}
				Sans = {X = 490 - 170*math.cos(math.rad(90/0.3*(NewAudio.GetPlayTime("One") - 17.7))), Y = 261}
				Encounter.Call("PapyrusAlpha", 0.5 + math.sin(math.rad(90/0.3*(NewAudio.GetPlayTime("One") - 17.7)))/2)
				Encounter.Call("SansAlpha", 0.5 + math.cos(math.rad(90/0.3*(NewAudio.GetPlayTime("One") - 17.7)))/2)
			else
				Encounter.Call("AttackAnim", 2)
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					Bubble("[noskip][font:papyrus][novoice]               \na [w:8][waittall:0.5][voice:papyrus pitched]m[novoice]  [w:10000000] ", "rightwide", 490.5, 395, 40, 90, 2)
					Bubble("[noskip][font:papyrus][voice:papyrus loud]Nyes, de vuelta\na [w:8][waittall:0.5][voice:papyrus pitched]m[novoice]í![w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
				else
					Bubble("[noskip][font:papyrus][novoice]             \n[w:10][waittall:0.5][voice:papyrus pitched]m[novoice]  [w:10000000] ", "rightwide", 490.5, 395, 40, 90, 2)
					Bubble("[noskip][font:papyrus][voice:papyrus loud]Nyes, back to\n[w:10][waittall:0.5][voice:papyrus pitched]m[novoice]e![w:10000000] ", "rightwide", 490.5, 395, 40, 90, 1)
				end
				Paps = {X = 330, Y = 240}
				Sans = {X = 490, Y = 261}
				Encounter.Call("PapyrusAlpha", 1)
				Encounter.Call("SansAlpha", 0.5)
				phases[1] = 19
			end
		elseif NewAudio.GetPlayTime("One") > 18.1 and phases[1] == 19 then
			Audio.PlaySound("gasterintro2")
			if state == 6 then
				table.insert(GB, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Type = "Papyrus", Animacion = {DatosIniciales = {X = -50, Y = 530, rotation = 0}, DatosFinales = {X = 190, Y = Player.absy, rotation = 90}}, Delay = 36, Duration = 30})
			elseif state == 4 then
				table.insert(GB, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Type = "Papyrus", Animacion = {DatosIniciales = {X = 690, Y = 530, rotation = 0}, DatosFinales = {X = 450, Y = Player.absy, rotation = -90}}, Delay = 36, Duration = 30})
			end
			phases[1] = 20
		elseif NewAudio.GetPlayTime("One") > 19.21 and phases[1] == 20 then
			Encounter.Call("AttackAnim", 2)
			phases[1] = 21
		elseif NewAudio.GetPlayTime("One") > 19.95 and phases[1] == 21 then
			Bubble("", "", 0, 0, 0, 0, 2)
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans][waittall:0.5]vamos hermano, un minuto\nsin interrupciones?[w:10000000] ", "leftwide", 310.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans][waittall:0.5]c'mon bro, just a minute\nwithout interruptions?[w:10000000] ", "leftwide", 310.5, 335, 10, 90, 1)
			end
			phases[1] = 22
		elseif NewAudio.GetPlayTime("One") > 21.75 and phases[1] == 22 then
			Bubble("", "", 0, 0, 0, 0, 1)
			if NewAudio.GetPlayTime("One") <= 22.05 then
				Paps = {X = 330 - 170*math.sin(math.rad(90/0.3*(NewAudio.GetPlayTime("One") - 21.75))), Y = 240}
				Sans = {X = 490 - 170*math.sin(math.rad(90/0.3*(NewAudio.GetPlayTime("One") - 21.75))), Y = 261}
				Encounter.Call("PapyrusAlpha", 1 - math.sin(math.rad(90/0.3*(NewAudio.GetPlayTime("One") - 21.75)))/2)
				Encounter.Call("SansAlpha", 0.5 + math.sin(math.rad(90/0.3*(NewAudio.GetPlayTime("One") - 21.75)))/2)
			else
				Paps = {X = 160, Y = 240}
				Sans = {X = 320, Y = 261}
				Encounter.Call("PapyrusAlpha", 0.5)
				Encounter.Call("SansAlpha", 1)
				phases[1] = 23
			end
		elseif NewAudio.GetPlayTime("One") > 22.05 and phases[1] == 23 then
			Audio.PlaySound("gasterintro")
			if state == 6 then
				table.insert(GB, {Sprite = CreateSprite("Bullets/GB Sans/0","BelowBullet"), Type = "Sans", Animacion = {DatosIniciales = {X = 690, Y = 530, rotation = 0}, DatosFinales = {X = 170, Y = Player.absy, rotation = 90}, VelAppearing = 45}, Delay = 55, Duration = 30})
			elseif state == 4 then
				table.insert(GB, {Sprite = CreateSprite("Bullets/GB Sans/0","BelowBullet"), Type = "Sans", Animacion = {DatosIniciales = {X = -50, Y = 530, rotation = 0}, DatosFinales = {X = 470, Y = Player.absy, rotation = -90}, VelAppearing = 45}, Delay = 55, Duration = 30})
			end
			phases[1] = 24
		elseif NewAudio.GetPlayTime("One") > 24.48 and phases[1] == 24 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans]necesito hablar con\nellos sobre lo que\nhicieron.[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans]i need to talk to\nthem about what they\ndid.[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
			end
			phases[1] = 25
		elseif NewAudio.GetPlayTime("One") > 24.76 + 0.82*(phases[1] - 25) and (phases[1] == 25 or phases[1] == 27) then
			local previous = state
			repeat
				state = math.random(3, 6)
			until state ~= 5 and state ~= previous
			RecolorSoul()
			jump = -100
			if state == 3 then
				Encounter["Sans"]["Animation"] = "Down"
				SummonWarning(1)
			elseif state == 4 then
				Encounter["Sans"]["Animation"] = "Left"
				SummonWarning(4)
			else
				Encounter["Sans"]["Animation"] = "Right"
				SummonWarning(2)
			end
			Encounter["Sans"]["Timer2"] = 0
			phases[1] = phases[1] + 1
		elseif NewAudio.GetPlayTime("One") > 25.5 + 0.82*(phases[1] - 26) and (phases[1] == 26 or phases[1] == 28) then
			DestroyWarning()
			if state == 3 then
				for i=Arena.x - Arena.width/2 + 5,Arena.x + Arena.width/2 - 5,12 do
					table.insert(HuesosSuelo, {Misil = CreateProjectileAbs("Bullets/Bones/BodyS", i, Arena.y + 5), Head = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Scale = {MaxHeight = 34, Vel = 4}, Duration = 20})
				end
			elseif state == 6 then
				for i=Arena.y + 10,Arena.y + Arena.height,12 do
					table.insert(HuesosSuelo, {Misil = CreateProjectileAbs("Bullets/Bones/BodyS", Arena.x + Arena.width/2, i), Head = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Scale = {MaxHeight = 34, Vel = 4}, Rotacion = 90, Duration = 20})
				end
			else
				for i=Arena.y + 10,Arena.y + Arena.height,12 do
					table.insert(HuesosSuelo, {Misil = CreateProjectileAbs("Bullets/Bones/BodyS", Arena.x - Arena.width/2, i), Head = CreateProjectileAbs("Bullets/Bones/HeadS", 0, 0), Scale = {MaxHeight = 34, Vel = 4}, Rotacion = 270, Duration = 20})
				end
			end
			phases[1] = phases[1] + 1
		elseif NewAudio.GetPlayTime("One") > 27.5 and phases[1] == 29 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans]porque si no lo hago...[func:SetSansHead,Yawn][w:10]\npodrían...[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans]because if I don't...[func:SetSansHead,Yawn][w:10]\nthey might...[w:10000000] ", "rightwide", 490.5, 315, 40, 90, 1)
			end
			phases[1] = 30
		elseif NewAudio.GetPlayTime("One") > 27.8 and phases[1] == 30 then
			local previous = state
			state = 5
			RecolorSoul()
			mantener = true
			Encounter["Sans"]["Animation"] = "Up"
			Encounter["Sans"]["Timer2"] = 0
			phases[1] = 31
		elseif NewAudio.GetPlayTime("One") > 30.4 and phases[1] == 31 then
			Encounter.Call("SetSansHead", "Sleepy")
			Encounter.Call("AttackAnim", 1)
			Encounter["Sans"]["Animation"] = "Stop"
			Encounter["Sans"]["Timer"] = 0
			Bubble("[noskip][font:sans][voice:sans]...", "rightwide", 490.5, 315, 40, 90, 1)
			phases[1] = 32
		elseif NewAudio.GetPlayTime("One") > 30.7 and phases[1] == 32 then
			Encounter.Call("SetSansHead", "zzz")
			Bubble("", "", 0, 0, 0, 0, 1)
			sleep = 0
			Encounter["Sans"]["Legs"].layer = "Bottom"
			Encounter["HandL"].layer = "BelowUI"
			Encounter["HandR"].layer = "BelowUI"
			Encounter["Legs"].layer = "BelowUI"
			phases[1] = 33
		elseif NewAudio.GetPlayTime("One") > 31.7 and phases[1] == 33 then
			Encounter.Call("SetHead", "Angry")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]EN SERIO?!?![w:10000000] ", "rightwide", 330.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]REALLY?!?![w:10000000] ", "rightwide", 330.5, 395, 40, 90, 1)
			end
			phases[1] = 34
		elseif NewAudio.GetPlayTime("One") > 32.7 and phases[1] == 34 then
			Encounter.Call("SetHead", "Thinking")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus]siempre haces\nesto...[w:10000000] ", "rightwide", 330.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus]You always do\nthis...[w:10000000] ", "rightwide", 330.5, 395, 40, 90, 1)
			end
			phases[1] = 35
		elseif NewAudio.GetPlayTime("One") > 34.65 and phases[1] == 35 then
			Encounter.Call("SetHead", "Disgust")
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus]Vaya[w:10], la\nsolución patética...[w:10000000] ", "rightwide", 330.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus]Alas[w:10], the\npathetic solution...[w:10000000] ", "rightwide", 330.5, 395, 40, 90, 1)
			end
			phases[1] = 36
		elseif NewAudio.GetPlayTime("One") > 37.8 and phases[1] == 36 then
			Encounter.Call("SetHead", "Normal 1")
			if not Ketchup then
				Ketchup = CreateSprite("Sans/Ketchup", "BelowUI")
				Ketchup.alpha = 0
				Encounter["HandL"].layer = "Top"
				Encounter["HandR"].layer = "Top"
				Encounter["Legs"].layer = "Top"
				Encounter["HandL"].layer = "BelowUI"
				Encounter["HandR"].layer = "BelowUI"
				Encounter["Legs"].layer = "BelowUI"
			end
			if NewAudio.GetPlayTime("One") > 38.2 and Ketchup.alpha <= 0 then
				Ketchup.alpha = 1
				Bubble("[noskip][font:papyrus][voice:papyrus]KETCHUP!!![w:10000000] ", "leftwide", 156.5, 395, 10, 90, 1)
			elseif Ketchup.alpha <= 0 then
				Bubble("", "", 0, 0, 0, 0, 1)
			end
			if NewAudio.GetPlayTime("One") <= 38.3 then
				Paps = {X = 160 + 170*math.sin(math.rad(90/0.4*math.min(NewAudio.GetPlayTime("One") - 37.8, 0.4))), Y = 240}
				Sans = {X = 540 - 220*math.cos(math.rad(90/0.5*(NewAudio.GetPlayTime("One") - 37.8))), Y = 261}
				Encounter["HandR"].rotation = -25*math.sin(math.rad(90/0.4*math.min(NewAudio.GetPlayTime("One") - 37.8, 0.4))) + 75*math.sin(math.rad(90/0.1*math.max(NewAudio.GetPlayTime("One") - 38.2, 0)))
				Encounter["HandL"].rotation = -5*math.sin(math.rad(90/0.4*math.min(NewAudio.GetPlayTime("One") - 37.8, 0.4))) + 45*math.sin(math.rad(90/0.1*math.max(NewAudio.GetPlayTime("One") - 38.2, 0)))
				Encounter["Body"].MoveTo(-8, 124 - 2*math.sin(math.rad(90/0.4*math.min(NewAudio.GetPlayTime("One") - 37.8, 0.4))) + 2*math.sin(math.rad(90/0.1*math.max(NewAudio.GetPlayTime("One") - 38.2, 0))))
				Encounter["HandR"].MoveTo(Paps.X + Encounter["Body"].x + 43 + 10*math.sin(math.rad(90/0.1*math.max(NewAudio.GetPlayTime("One") - 38.2, 0))), Paps.Y + Encounter["Body"].y + 7 - 10*math.cos(math.rad(90/0.1*math.max(NewAudio.GetPlayTime("One") - 38.2, 0))))
				Ketchup.MoveTo(Encounter["HandR"].x + 36*math.sin(math.rad(90/0.1*math.max(NewAudio.GetPlayTime("One") - 38.2, 0)))*math.cos(math.rad(Encounter["HandR"].rotation)) + 70*math.sin(math.rad(90/0.1*math.max(NewAudio.GetPlayTime("One") - 38.2, 0)))*math.sin(math.rad(Encounter["HandR"].rotation)), Encounter["HandR"].y - 70*math.sin(math.rad(90/0.1*math.max(NewAudio.GetPlayTime("One") - 38.2, 0)))*math.cos(math.rad(Encounter["HandR"].rotation)) + 36*math.sin(math.rad(90/0.1*math.max(NewAudio.GetPlayTime("One") - 38.2, 0)))*math.sin(math.rad(Encounter["HandR"].rotation)))
				Ketchup.rotation = 210 + Encounter["HandR"].rotation
				Encounter.Call("PapyrusAlpha", 0.5 + math.sin(math.rad(90/0.4*math.min(NewAudio.GetPlayTime("One") - 37.8, 0.4)))/2)
				Encounter.Call("SansAlpha", 0.5 + math.cos(math.rad(90/0.5*(NewAudio.GetPlayTime("One") - 37.8)))/2)
				for i=1,#Encounter["LegsParts"] do
					local sprite = Encounter["LegsParts"][i]
					sprite.MoveTo(Encounter["PiernasX"] + sprite.GetVar("intensity")*math.sin(math.rad(20/0.1*math.max(NewAudio.GetPlayTime("One") - 38.2, 0))), Encounter["PiernasY"] + sprite.GetVar("Y"))
				end
			else
				Paps = {X = 330, Y = 240}
				Sans = {X = 540, Y = 261}
				Encounter["HandR"].rotation = 50
				Encounter["HandL"].rotation = 40
				Encounter["Body"].MoveTo(-8, 124)
				Encounter["HandR"].MoveTo(Paps.X + Encounter["Body"].x + 53, Paps.Y + Encounter["Body"].y + 7)
				Ketchup.MoveTo(Encounter["HandR"].x + 36*math.cos(math.rad(Encounter["HandR"].rotation)) + 70*math.sin(math.rad(Encounter["HandR"].rotation)), Encounter["HandR"].y - 70*math.cos(math.rad(Encounter["HandR"].rotation)) + 36*math.sin(math.rad(Encounter["HandR"].rotation)))
				Ketchup.rotation = 210 + Encounter["HandR"].rotation
				Encounter.Call("PapyrusAlpha", 1)
				Encounter.Call("SansAlpha", 0.5)
				for i=1,#Encounter["LegsParts"] do
					local sprite = Encounter["LegsParts"][i]
					sprite.MoveTo(Encounter["PiernasX"] + sprite.GetVar("intensity")*math.sin(math.rad(20)), Encounter["PiernasY"] + sprite.GetVar("Y"))
				end
				phases[1] = 37
			end
			Encounter["HandL"].MoveTo(Paps.X + Encounter["Body"].x - 44, Paps.Y + Encounter["Body"].y - 13)
		elseif NewAudio.GetPlayTime("One") > 38.5 and phases[1] == 37 then
			if NewAudio.GetPlayTime("One") <= 38.7 then
				Encounter["HandR"].rotation = 50 - 5*math.sin(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 38.5)))
				Encounter["HandL"].rotation = 40*math.cos(math.rad(45/0.2*(NewAudio.GetPlayTime("One") - 38.5)))
				Ketchup.MoveTo(Encounter["HandR"].x + 36*math.cos(math.rad(Encounter["HandR"].rotation)) + 70*math.sin(math.rad(Encounter["HandR"].rotation)), Encounter["HandR"].y - 70*math.cos(math.rad(Encounter["HandR"].rotation)) + 36*math.sin(math.rad(Encounter["HandR"].rotation)))
				Ketchup.rotation = 210 + Encounter["HandR"].rotation + 45/0.2*(NewAudio.GetPlayTime("One") - 38.5)
				for i=1,#Encounter["LegsParts"] do
					local sprite = Encounter["LegsParts"][i]
					sprite.MoveTo(Encounter["PiernasX"] + sprite.GetVar("intensity")*math.sin(math.rad(20 - 10/0.2*(NewAudio.GetPlayTime("One") - 38.5))), Encounter["PiernasY"] + sprite.GetVar("Y"))
				end
			else
				Encounter["HandR"].rotation = 45
				Encounter["HandL"].rotation = 40*math.cos(math.rad(45))
				Ketchup.MoveTo(Encounter["HandR"].x + 36*math.cos(math.rad(Encounter["HandR"].rotation)) + 70*math.sin(math.rad(Encounter["HandR"].rotation)), Encounter["HandR"].y - 70*math.cos(math.rad(Encounter["HandR"].rotation)) + 36*math.sin(math.rad(Encounter["HandR"].rotation)))
				Ketchup.rotation = 255 + Encounter["HandR"].rotation
				for i=1,#Encounter["LegsParts"] do
					local sprite = Encounter["LegsParts"][i]
					sprite.MoveTo(Encounter["PiernasX"] + sprite.GetVar("intensity")*math.sin(math.rad(10)), Encounter["PiernasY"] + sprite.GetVar("Y"))
				end
				phases[1] = 38
			end
		elseif NewAudio.GetPlayTime("One") > 38.7 and phases[1] == 38 then
			Encounter["HandR"].Set("Papyrus/Arms/CrusherR Inv")
			Encounter["HandR"].SetPivot(3/72, 50/56)
			if NewAudio.GetPlayTime("One") <= 38.9 then
				Encounter["HandR"].rotation = 30 - 45*math.cos(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 38.7)))
				Encounter["HandL"].rotation = 40*math.cos(math.rad(45 + 45/0.2*(NewAudio.GetPlayTime("One") - 38.7)))
				Ketchup.MoveTo(Encounter["HandR"].x + 66*math.cos(math.rad(Encounter["HandR"].rotation)) + 36*math.sin(math.rad(Encounter["HandR"].rotation)), Encounter["HandR"].y - 36*math.cos(math.rad(Encounter["HandR"].rotation)) + 66*math.sin(math.rad(Encounter["HandR"].rotation)))
				for i=1,#Encounter["LegsParts"] do
					local sprite = Encounter["LegsParts"][i]
					sprite.MoveTo(Encounter["PiernasX"] + sprite.GetVar("intensity")*math.sin(math.rad(10 - 10/0.2*(NewAudio.GetPlayTime("One") - 38.7))), Encounter["PiernasY"] + sprite.GetVar("Y"))
				end
				Ketchup.rotation = 315 + 90/0.2*(NewAudio.GetPlayTime("One") - 38.7) + Encounter["HandR"].rotation
			else
				Encounter["HandR"].rotation = 30
				Encounter["HandL"].rotation = 0
				Ketchup.MoveTo(Encounter["HandR"].x + 66*math.cos(math.rad(Encounter["HandR"].rotation)) + 36*math.sin(math.rad(Encounter["HandR"].rotation)), Encounter["HandR"].y - 36*math.cos(math.rad(Encounter["HandR"].rotation)) + 66*math.sin(math.rad(Encounter["HandR"].rotation)))
				Ketchup.rotation = 45 + Encounter["HandR"].rotation
				for i=1,#Encounter["LegsParts"] do
					local sprite = Encounter["LegsParts"][i]
					sprite.MoveTo(Encounter["PiernasX"], Encounter["PiernasY"] + sprite.GetVar("Y"))
				end
				Encounter.Call("SetHead", "Happy")
				phases[1] = 39
			end
		elseif NewAudio.GetPlayTime("One") > 38.9 and phases[1] == 39 then
			if NewAudio.GetPlayTime("One") <= 39.4 then
				Ketchup.MoveTo(Encounter["HandR"].x + (66 + 8/0.5*(NewAudio.GetPlayTime("One") - 38.9))*math.cos(math.rad(Encounter["HandR"].rotation)) + (36 + 14/0.5*(NewAudio.GetPlayTime("One") - 38.9))*math.sin(math.rad(Encounter["HandR"].rotation)), Encounter["HandR"].y - (36 + 14/0.5*(NewAudio.GetPlayTime("One") - 38.9))*math.cos(math.rad(Encounter["HandR"].rotation)) + (66 + 8/0.5*(NewAudio.GetPlayTime("One") - 38.9))*math.sin(math.rad(Encounter["HandR"].rotation)))
			else
				Ketchup.MoveTo(Encounter["HandR"].x + 74*math.cos(math.rad(Encounter["HandR"].rotation)) + 50*math.sin(math.rad(Encounter["HandR"].rotation)), Encounter["HandR"].y - 50*math.cos(math.rad(Encounter["HandR"].rotation)) + 74*math.sin(math.rad(Encounter["HandR"].rotation)))
				Bubble("[noskip][font:papyrus][voice:papyrus]Whoops[w:10000000] ", "leftwide", 156.5, 395, 10, 90, 1)
				phases[1] = 40
			end
		elseif NewAudio.GetPlayTime("One") > 39.4 and phases[1] == 40 then
			if NewAudio.GetPlayTime("One") <= 39.8 then
				Ketchup.MoveTo(464 + 6/0.4*(NewAudio.GetPlayTime("One") - 39.4), 262 + 102.5*math.cos(math.rad(90/0.4*(NewAudio.GetPlayTime("One") - 39.4))))
				Ketchup.rotation = 75*math.cos(math.rad(90/0.4*(NewAudio.GetPlayTime("One") - 39.4)))
			else
				Ketchup.MoveTo(470, 262)
				Ketchup.rotation = 0
				phases[1] = 41
			end
		elseif NewAudio.GetPlayTime("One") > 39.8 and phases[1] == 41 then
			if NewAudio.GetPlayTime("One") <= 39.9 then
				Ketchup.MoveTo(470 + 2/0.1*(NewAudio.GetPlayTime("One") - 39.8), 262 + 26*math.sin(math.rad(90/0.1*(NewAudio.GetPlayTime("One") - 39.8))))
				Ketchup.rotation = -20*math.sin(math.rad(90/0.1*(NewAudio.GetPlayTime("One") - 39.8)))
			else
				Ketchup.MoveTo(472, 288)
				Ketchup.rotation = -20
				Bubble("", "", 0, 0, 0, 0, 1)
				sleep = nil
				Encounter["Sans"]["Head"].SetAnimation({"Sans/Head/Power 1", "Sans/Head/Power 2"}, 0.04)
				Audio.PlaySound("ding")
				NewAudio.CreateChannel("Sans")
				NewAudio.PlaySound("Sans", "Voices/sans fast", true, 1)
				phases[1] = 42
			end
		elseif NewAudio.GetPlayTime("One") > 39.9 and phases[1] == 42 then
			if NewAudio.GetPlayTime("One") <= 40.1 then
				Ketchup.alpha = 1/0.2*(40.1 - NewAudio.GetPlayTime("One"))
				Encounter.Call("SansAlpha", 0.5 + 0.5/0.2*(NewAudio.GetPlayTime("One") - 39.9))
			else
				Ketchup.alpha = 0
				Ketchup.MoveTo(532, 312)
				Encounter.Call("SansAlpha", 1)
				phases[1] = 43
			end
		elseif NewAudio.GetPlayTime("One") > 40.2 and phases[1] == 43 then
			if NewAudio.GetPlayTime("One") <= 40.4 then
				Ketchup.alpha = 1/0.2*(NewAudio.GetPlayTime("One") - 40.2)
			else
				Ketchup.alpha = 1
				Encounter["Sans"]["Head"].StopAnimation()
				Encounter.Call("SetSansHead", "Yummy")
				Audio.PlaySound("ding")
				NewAudio.Stop("Sans")
				NewAudio.DestroyChannel("Sans")
				phases[1] = 44
			end
		elseif NewAudio.GetPlayTime("One") > 40.4 and phases[1] == 44 then
			if NewAudio.GetPlayTime("One") <= 40.6 then
				Ketchup.MoveTo(532, 277 + 30*math.cos(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 40.4))))
				Ketchup.alpha = 1/0.2*(40.6 - NewAudio.GetPlayTime("One"))
				Ketchup.rotation = -20 - 50*(NewAudio.GetPlayTime("One") - 40.6)
			else
				Ketchup.Remove()
				Ketchup = nil
				Encounter.Call("SetHead", "Angry")
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Esperaba que mi\nplan fallara.[w:10000000] ", "leftwide", 156.5, 395, 10, 90, 1)
				else
					Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]I was hoping my\nplan would fail.[w:10000000] ", "leftwide", 156.5, 395, 10, 90, 1)
				end
				Encounter["HandL"].Set("Papyrus/Arms/CrabL")
				Encounter["HandR"].Set("Papyrus/Arms/CrabR")
				Encounter["HandL"].SetPivot(0.5, 0.5)
				Encounter["HandR"].SetPivot(0.5, 0.5)
				Encounter["HandL"].MoveTo(284, 314)
				Encounter["HandR"].MoveTo(365, 322)
				Encounter["HandR"].rotation = 0
				Encounter["ignore"] = true
				phases[1] = 45
			end
		elseif NewAudio.GetPlayTime("One") > 42.2 and phases[1] == 45 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans]heh[w:10], supongo que podrías\ndecir que eres muy bueno para el chico.[w:10000000] ", "leftwide", 360.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans]heh[w:10], guess you could\nsay that you're so good for the kiddo.[w:10000000] ", "leftwide", 360.5, 335, 10, 90, 1)
			end
			phases[1] = 46
		elseif NewAudio.GetPlayTime("One") > 43.5 and phases[1] == 46 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Sans[w:5], baja tu\nbrazo.[w:10000000] ", "leftwide", 156.5, 395, 10, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:papyrus][waittall:0.5]Sans[w:5], take your\narm down.[w:10000000] ", "leftwide", 156.5, 395, 10, 90, 1)
			end
			phases[1] = 47
		elseif NewAudio.GetPlayTime("One") > 45.3 and phases[1] == 47 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans][waittall:0.5]es [color:ff0000]braz-tante[color:000000] importante?[w:10000000] ", "leftwide", 360.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans][waittall:0.5]is it an [color:ff0000]arm-ergency[color:000000]?[w:10000000] ", "leftwide", 360.5, 335, 10, 90, 1)
			end
			phases[1] = 48
		elseif NewAudio.GetPlayTime("One") > 46.2 and phases[1] == 48 then
			Bubble("[noskip][font:papyrus][voice:papyrus loud][waittall:0.5]SANS!!![w:10000000] ", "leftwide", 156.5, 395, 10, 90, 1)
			phases[1] = 49
		elseif NewAudio.GetPlayTime("One") > 46.6 and phases[1] == 49 then
			Encounter.Call("SetSansHead", "Normal")
			Encounter["Sans"]["Body"].Set("Sans/Body/Left")
			state = 3
			RecolorSoul()
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:sans][voice:sans][waittall:0.5]solo bromeo hermano.[w:10000000] ", "leftwide", 360.5, 335, 10, 90, 1)
			else
				Bubble("[noskip][font:sans][voice:sans][waittall:0.5]i'm just joking bro.[w:10000000] ", "leftwide", 360.5, 335, 10, 90, 1)
			end
			Encounter["Sans"]["Timer"] = 0
			phases[1] = 50
		elseif NewAudio.GetPlayTime("One") > 47.5 and phases[1] == 50 then
			Bubble("", "", 0, 0, 0, 0, 1)
			Encounter["Sans"]["Animation"] = "Normal"
			if NewAudio.GetPlayTime("One") <= 48 then
				Paps = {X = 285 + 45*math.cos(math.rad(180/0.5*(NewAudio.GetPlayTime("One") - 47.5))), Y = 240}
				Sans = {X = 475 + 65*math.cos(math.rad(180/0.5*(NewAudio.GetPlayTime("One") - 47.5))), Y = 261}
				Encounter["HandL"].MoveTo(239 + 45*math.cos(math.rad(180/0.5*(NewAudio.GetPlayTime("One") - 47.5))), 314)
				Encounter["HandR"].MoveTo(320 + 45*math.cos(math.rad(180/0.5*(NewAudio.GetPlayTime("One") - 47.5))), 322)
			else
				Paps = {X = 240, Y = 240}
				Sans = {X = 410, Y = 261}
				Encounter["HandL"].MoveTo(194, 314)
				Encounter["HandR"].MoveTo(275, 322)
			end
		end
		if NewAudio.GetPlayTime("One") > 3.9 and phases[2] == 0 and FakeKR then
			if NewAudio.GetPlayTime("One") <= 4.05 then
				FakeKR.Scale(1 + (NewAudio.GetPlayTime("One") - 3.9)/0.15, 1 + (NewAudio.GetPlayTime("One") - 3.9)/0.15)
				FakeKR.alpha = (NewAudio.GetPlayTime("One") - 3.9)/0.15
			else
				FakeKR.Scale(2, 2)
				FakeKR.alpha = 1
				phases[2] = 1
			end
		end
		if (NewAudio.isStopped("One") and Encounter["GameMusic"] ~= "Loop 1" and Encounter["GameMusic"] ~= "Continue 1") or NewAudio.GetPlayTime("One") > 48 then
			endAll = true
		end
	end
	if Heart then
		Heart.MoveTo(Player.absx, Player.absy)
		if phases[1] >= 3 and not Player.isHurting then
			Heart.Remove()
			Heart = nil
		end
	end
	if mantener then
		jump = -10
	end
	if sleep then
		sleep = sleep + 1
		if sleep%15 == 0 and sleep <= 45 then
			table.insert(Z, {Sprite = CreateSprite("Sans/Z", "Bottom"), Timer = 0})
			Encounter["Sans"]["Legs"].layer = "Top"
			Encounter["Sans"]["Legs"].layer = "Bottom"
		elseif sleep > 120 then
			sleep = 0
		end
	end
	shake = {}
	if slamtimer > 0 then
		slamtimer = slamtimer - 1
		shake = {math.random(-4, 4), math.random(-4, 4)}
	end
	if endAll then
		Bubble("", "", 0, 0, 0, 0, 1)
		Bubble("", "", 0, 0, 0, 0, 2)
		Paps = {X = 240, Y = 240}
		Sans = {X = 410, Y = 261}
		Encounter["Sans"]["Head"].StopAnimation()
		Encounter.Call("SetSansHead", "Normal")
		Encounter.Call("SetHead", "Normal 1")
		Encounter.Call("SansAlpha", 1)
		Encounter.Call("PapyrusAlpha", 1)
		Encounter["Sans"]["Animation"] = "Normal"
		Encounter["Animation"] = "Calmado"
		Encounter["ignore"] = nil
		Encounter["HandL"].Set("Papyrus/Arms/CrusherL")
		Encounter["HandR"].Set("Papyrus/Arms/CrusherR")
		Encounter["HandL"].SetPivot(33/36, 27/74)
		Encounter["HandR"].SetPivot(6/56, 69/72)
		Encounter["HandL"].MoveTo(Encounter["PiernasX"] + Encounter["Body"].x - 44, Encounter["PiernasY"] + Encounter["Body"].y - 13)
		Encounter["HandR"].MoveTo(Encounter["PiernasX"] + Encounter["Body"].x + 43, Encounter["PiernasY"] + Encounter["Body"].y - 3)
		Encounter.Call("SetCustomHP", {200, 19, 184, Player.hp, true})
		EndWave()
	end
	for i=1,#Z do
		local Datos = Z[i - tableaux]
		if Datos then
			Datos.Timer = Datos.Timer + 1
			Datos.Sprite.MoveTo(Encounter["Sans"]["Head"].absx + Datos.Timer*1.5 - 5*math.cos(math.rad(90/20*Datos.Timer)), Encounter["Sans"]["Head"].absy + Datos.Timer - 5*math.sin(math.rad(90/20*Datos.Timer)))
			Datos.Sprite.Scale(1.25 + math.cos(math.rad(90/20*(Datos.Timer + 15)))/4, 1.25 + math.cos(math.rad(90/20*(Datos.Timer + 15)))/4)
			Datos.Sprite.color = Encounter["Sans"]["Head"].color
			if Encounter["Sans"]["Head"].absy + Datos.Timer >= 520 then
				Datos.Sprite.Remove()
				table.remove(Z, i - tableaux)
				tableuax = tableaux + 1
			end
		end
	end
	tableaux = 0
	for i=1,#GB do
		local gb = GB[i - tableaux]
		if not gb.X then
			gb.X = gb.Sprite.x
		end
		if not gb.Y then
			gb.Y = gb.Sprite.y
		end
		if gb.Type == "Papyrus" then
			gb.distance = 26
		elseif gb.Type == "Sans" then
			gb.distance = 38
		end
		gb.Sprite.xscale = (gb.Scale or 1)
		if gb.Animacion then
			if not gb.Animacion.timer then
				gb.Animacion.timer = 0
			end
			gb.Animacion.timer = gb.Animacion.timer + 1
			gb.X = gb.Animacion.DatosIniciales.X + (gb.Animacion.DatosFinales.X - gb.Animacion.DatosIniciales.X)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			gb.Y = gb.Animacion.DatosIniciales.Y + (gb.Animacion.DatosFinales.Y - gb.Animacion.DatosIniciales.Y)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			gb.Sprite.MoveTo(gb.X, gb.Y)
			while gb.Animacion.DatosIniciales.rotation >= 360 or gb.Animacion.DatosIniciales.rotation < 0 do
				if gb.Animacion.DatosIniciales.rotation < 0 then
					gb.Animacion.DatosIniciales.rotation = gb.Animacion.DatosIniciales.rotation + 360
				else
					gb.Animacion.DatosIniciales.rotation = gb.Animacion.DatosIniciales.rotation - 360
				end
			end
			while gb.Animacion.DatosFinales.rotation >= 360 or gb.Animacion.DatosFinales.rotation < 0 do
				if gb.Animacion.DatosFinales.rotation < 0 then
					gb.Animacion.DatosFinales.rotation = gb.Animacion.DatosFinales.rotation + 360
				else
					gb.Animacion.DatosFinales.rotation = gb.Animacion.DatosFinales.rotation - 360
				end
			end
			if gb.Animacion.DatosFinales.rotation - gb.Animacion.DatosIniciales.rotation <= 180 and gb.Animacion.DatosFinales.rotation - gb.Animacion.DatosIniciales.rotation >= -180 then
				gb.Sprite.rotation = gb.Animacion.DatosIniciales.rotation - (gb.Animacion.DatosIniciales.rotation - gb.Animacion.DatosFinales.rotation)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			else
				gb.Sprite.rotation = gb.Animacion.DatosIniciales.rotation - (360 - (gb.Animacion.DatosFinales.rotation - 180 + gb.Animacion.DatosIniciales.rotation - 180)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30)))))
			end
			if gb.Animacion.timer >= (gb.Animacion.VelAppearing or 30) then
				gb.Animacion = nil
				gb.Done = true
			end
		else
			if gb.Rotation and not gb.Done then
				gb.Sprite.rotation = gb.Rotation
			end
			gb.Delay = gb.Delay - 1
		end
		if gb.Vel then
			gb.X = gb.X - gb.Vel*math.sin(math.rad(gb.Sprite.rotation))
			gb.Y = gb.Y + gb.Vel*math.cos(math.rad(gb.Sprite.rotation))
			gb.Vel = gb.Vel*1.1
			if gb.X < -100 or gb.X > 740 or gb.Y < -100 or gb.Y > 580 then
				gb.Vel = 0
			end
		end
		gb.Sprite.MoveTo(gb.X, gb.Y)
		if (gb.Delay < 0 and gb.Type == "Papyrus") or (gb.Delay < 6 and gb.Type == "Sans") then
			if gb.Delay == 5 then
				gb.Sprite.Set("Bullets/GB Sans/1")
			elseif gb.Delay == 3 then
				gb.Sprite.Set("Bullets/GB Sans/2")
			elseif gb.Delay == 1 then
				gb.Sprite.Set("Bullets/GB Sans/3")
			elseif gb.Delay == -1 then
				if gb.Type == "Papyrus" then
					gb.Sprite.Set("Bullets/GB Papyrus/1")
				else
					gb.Sprite.SetAnimation({"Bullets/GB Sans/4","Bullets/GB Sans/5"}, 0.04)
				end
				gb.Vel = 2
				Audio.PlaySound("gasterfire")
			elseif gb.Delay <= -2 then
				if gb.Duration > 0 then
					gb.Duration = gb.Duration - 1
					if not gb.Laser then
						gb.Laser = {Misil = CreateProjectileAbs("Bullets/GB Laser", gb.X + (640 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (640 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))}
						gb.Laser.Misil.sprite.xscale = 0
						gb.Laser.Misil.sprite.rotation = gb.Sprite.rotation
						gb.Laser.Scale = 0
					else
						gb.Laser.Misil.MoveToAbs(gb.X + (640 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (640 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						if gb.Laser.Misil.sprite.xscale < 0.9*gb.Sprite.xscale and gb.Laser.Scale == 0 then
							gb.Laser.Misil.sprite.xscale = gb.Laser.Misil.sprite.xscale + 0.1*gb.Sprite.xscale
						else
							gb.Laser.Scale = gb.Laser.Scale + 50
							gb.Laser.Misil.sprite.xscale = 0.9*gb.Sprite.xscale + 0.1*gb.Sprite.xscale*math.sin(math.rad(gb.Laser.Scale))
						end
					end
					if #shake == 0 then
						shake = {math.random(-4, 4), math.random(-4, 4)}
					end
				else
					gb.Laser.Misil.SetVar("No Damage", true)
					if gb.Laser.Misil.sprite.xscale > 0 then
						gb.Laser.Misil.MoveToAbs(gb.X + (640 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (640 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						gb.Laser.Misil.sprite.xscale = gb.Laser.Misil.sprite.xscale - 0.05*gb.Sprite.xscale
						gb.Laser.Misil.sprite.alpha = gb.Laser.Misil.sprite.xscale
					else
						gb.Laser.Misil.Remove()
						gb.Sprite.Remove()
						gb = nil
						table.remove(GB, i - tableaux)
						tableaux = tableaux + 1
					end
				end
			end
		end
		if gb and shake then
			gb.Sprite.MoveTo(gb.X + (shake[1] or 0), gb.Y + (shake[2] or 0))
			if gb.Laser then
				gb.Laser.Misil.Move((shake[1] or 0), (shake[2] or 0))
			end
		end
	end
	tableaux = 0
	Arena.MoveTo(320 + (shake[1] or 0), 90 + (shake[2] or 0), false, true)
	Encounter.Call("PapsMoveTo", {Paps.X + (shake[1] or 0), Paps.Y + (shake[2] or 0)})
	Encounter["Sans"]["Legs"].MoveTo(Sans.X + (shake[1] or 0), Sans.Y + (shake[2] or 0))
	Encounter.Call("StatusMoveTo", {320 + (shake[1] or 0), 70.5 + (shake[2] or 0)})
	Encounter.Call("ButtonMoveTo", {"Fight", 87 + (shake[1] or 0), 27 + (shake[2] or 0)})
	Encounter.Call("ButtonMoveTo", {"Act", 240 + (shake[1] or 0), 27 + (shake[2] or 0)})
	Encounter.Call("ButtonMoveTo", {"Item", 400 + (shake[1] or 0), 27 + (shake[2] or 0)})
	Encounter.Call("ButtonMoveTo", {"Mercy", 555 + (shake[1] or 0), 27 + (shake[2] or 0)})
	for i=1,#Sprites do
		if Sprites[i - tableaux].isactive then
			Sprites[i - tableaux].MoveTo(Sprites[i - tableaux].GetVar("Pos")[1] + (shake[1] or 0), Sprites[i - tableaux].GetVar("Pos")[2] + (shake[2] or 0))
		else
			table.remove(Sprites, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#Bones do
		local Datos = Bones[i - tableaux]
		if not Datos.X then
			Datos.X = Datos.Body.absx
		end
		if not Datos.Y then
			Datos.Y = Datos.Body.absy
		end
		Datos.X = Datos.X + Datos.Vel
		Datos.Body.sprite.yscale = Datos.Scale
		Datos.Legs.sprite.rotation = 180
		Datos.Body.MoveToAbs(Datos.X, Datos.Y)
		Datos.Head.MoveToAbs(Datos.X, Datos.Y + Datos.Scale/2 + 2.5)
		Datos.Legs.MoveToAbs(Datos.X, Datos.Y - Datos.Scale/2 - 2.5)
		if Datos.X <= Arena.x - Arena.width/2 - 2 then
			Datos.Body.Remove()
			Datos.Head.Remove()
			Datos.Legs.Remove()
			table.remove(Bones, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#HuesosSuelo do
		local bullet = HuesosSuelo[i - tableaux]
		if not bullet.X then
			bullet.X = bullet.Misil.absx
		end
		if not bullet.Y then
			bullet.Y = bullet.Misil.absy
		end
		if not bullet.Scale.Direction then
			bullet.Scale.Direction = "Up"
		end
		if not bullet.Scale.Current then
			bullet.Scale.Current = 0
		end
		if not bullet.Rotacion then
			bullet.Rotacion = 0
		end
		if bullet.Scale.Current < bullet.Scale.MaxHeight and bullet.Scale.Direction == "Up" then
			bullet.Scale.Current = math.min(bullet.Scale.Current + bullet.Scale.Vel, bullet.Scale.MaxHeight)
			if bullet.Scale.Current >= bullet.Scale.MaxHeight then
				bullet.Scale.Direction = "Waiting"
			end
		elseif bullet.Scale.Direction == "Waiting" then
			if not bullet.Timer then
				bullet.Timer = 0
			end
			bullet.Timer = bullet.Timer + 1
			if bullet.Timer >= (bullet.Duration or 30) then
				bullet.Scale.Direction = "Down"
			end
		elseif bullet.Scale.Current > 0 and bullet.Scale.Direction == "Down" then
			bullet.Scale.Current = math.max(bullet.Scale.Current - bullet.Scale.Vel, 0)
		end
		bullet.Misil.sprite.yscale = bullet.Scale.Current
		bullet.Misil.sprite.rotation = bullet.Rotacion
		bullet.Misil.MoveToAbs(bullet.X + (shake[1] or 0) - bullet.Scale.Current/2*math.sin(math.rad(bullet.Rotacion)), bullet.Y + (shake[2] or 0) + bullet.Scale.Current/2*math.cos(math.rad(bullet.Rotacion)))
		if bullet.Head then
			bullet.Head.MoveToAbs(bullet.X + (shake[1] or 0) - (bullet.Scale.Current + 3)*math.sin(math.rad(bullet.Rotacion)), bullet.Y + (shake[2] or 0) + (bullet.Scale.Current + 3)*math.cos(math.rad(bullet.Rotacion)))
			bullet.Head.sprite.rotation = bullet.Rotacion
		end
		if bullet.Legs then
			bullet.Legs.MoveToAbs(bullet.X + (shake[1] or 0) + (bullet.Scale.Current + 3)*math.sin(math.rad(bullet.Rotacion)), bullet.Y + (shake[2] or 0) - (bullet.Scale.Current + 3)*math.cos(math.rad(bullet.Rotacion)))
			bullet.Legs.sprite.rotation = bullet.Rotacion + 180
		end
		if bullet.Scale.Current <= 0 and bullet.Scale.Direction == "Down" then
			bullet.Misil.Remove()
			if bullet.Head then
				bullet.Head.Remove()
			end
			if bullet.Legs then
				bullet.Legs.Remove()
			end
			bullet = nil
			table.remove(HuesosSuelo, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	if state == 1 then -- Down
		if newpY > 85 + Arena.height and jump > 0 then
			newpY = 87 + Arena.height
			jump = 0
		elseif newpY < 105 then
			newpY = 103
			jump = 0
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Up < 0 and jump > 3 then
			jump = 2
		end
		newpY = math.max(newpY + (jump/10), 103)
		if newpX < 328 - Arena.width/2 then
			newpX = 328 - Arena.width/2
		elseif newpX > 312 + Arena.width/2 then
			newpX = 312 + Arena.width/2
		end
		Player.MoveToAbs(newpX + (shake[1] or 0), newpY + (shake[2] or 0), true)
	elseif state == 2 then -- Down
		if Input.Right > 0 then
			newpX = newpX + 3
		end
		if Input.Left > 0 then
			newpX = newpX - 3
		end
		if newpY > 85 + Arena.height and jump > 0 then
			newpY = 87 + Arena.height
			jump = 0
		elseif newpY < 105 then
			if Input.Up > 0 then
				jump = maxjump
			else
				newpY = 103
				jump = 0
			end
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Up < 0 and jump > 3 then
			jump = 2
		end
		newpY = math.max(newpY + (jump/10), 103)
		if newpX < 328 - Arena.width/2 then
			newpX = 328 - Arena.width/2
		elseif newpX > 312 + Arena.width/2 then
			newpX = 312 + Arena.width/2
		end
		Player.MoveToAbs(newpX + (shake[1] or 0), newpY + (shake[2] or 0), true)
	elseif state == 3 then -- Down
		if Input.Right > 0 then
			newpX = newpX + 3
		end
		if Input.Left > 0 then
			newpX = newpX - 3
		end
		if newpY < 105 then
			if Input.Up > 0 then
				jump = maxjump
			else
				newpY = 103
				jump = 0
			end
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Up < 0 and jump > 3 then
			jump = 2
		end
		newpY = math.max(newpY + (jump/10), 103)
		if newpX < 328 - Arena.width/2 then
			newpX = 328 - Arena.width/2
		elseif newpX > 312 + Arena.width/2 then
			newpX = 312 + Arena.width/2
		end
		Player.MoveToAbs(newpX + (shake[1] or 0), newpY + (shake[2] or 0), true)
    elseif state == 4 then -- Left
		if Input.Up > 0 then
			newpY = newpY + 3
		end
		if Input.Down > 0 then
			newpY = newpY - 3
		end
		if newpX < 330 - Arena.width/2 then
			if jump < -100 and phases[1] <= 18 then
				slamtimer = 10
			end
			if Input.Right > 0 then
				jump = maxjump
			else
				newpX = 328 - Arena.width/2
				jump = 0
			end
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Right < 0 and jump > 3 then
			jump = 2
		end
		newpX = math.max(newpX + (jump/10), 328 - Arena.width/2)
		if newpY < 103 then
			newpY = 103
		elseif newpY > 87 + Arena.height then
			newpY = 87 + Arena.height
		end
		Player.MoveToAbs(newpX + (shake[1] or 0), newpY + (shake[2] or 0), true)
	elseif state == 5 then -- Up
		if Input.Right > 0 then
			newpX = newpX + 3
		end
		if Input.Left > 0 then
			newpX = newpX - 3
		end
		if newpY > 85 + Arena.height then
			if Input.Down > 0 then
				jump = maxjump
			else
				newpY = 87 + Arena.height
				jump = 0
			end
			mantener = nil
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Down < 0 and jump > 3 then
			jump = 2
		end
		newpY = math.min(newpY - (jump/10), 87 + Arena.height)
		if newpX < 328 - Arena.width/2 then
			newpX = 328 - Arena.width/2
		elseif newpX > 312 + Arena.width/2 then
			newpX = 312 + Arena.width/2
		end
		Player.MoveToAbs(newpX + (shake[1] or 0), newpY + (shake[2] or 0), true)
    elseif state == 6 then -- Right
		if Input.Up > 0 then
			newpY = newpY + 3
		end
		if Input.Down > 0 then
			newpY = newpY - 3
		end
		if newpX > 310 + Arena.width/2 then
			if jump < -100 and phases[1] <= 18 then
				slamtimer = 10
			end
			if Input.Left > 0 then
				jump = maxjump
			else
				newpX = 312 + Arena.width/2
				jump = 0
			end
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Left < 0 and jump > 3 then
			jump = 2
		end
		newpX = math.min(newpX - (jump/10), 312 + Arena.width/2)
		if newpY < 103 then
			newpY = 103
		elseif newpY > 87 + Arena.height then
			newpY = 87 + Arena.height
		end
		Player.MoveToAbs(newpX + (shake[1] or 0), newpY + (shake[2] or 0), true)
    end
end

function OnHit(bullet)
	if not bullet.GetVar("No Damage") then
		Player.Hurt(20)
		Encounter["NOHIT"] = nil
	end
end